package com.mingrisoft;import static java.lang.Runtime.getRuntime;import java.awt.BorderLayout;import java.awt.Color;import java.awt.EventQueue;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.IOException;import java.util.Scanner;import javax.swing.JButton;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.border.BevelBorder;import javax.swing.border.EmptyBorder;import javax.swing.border.TitledBorder;import javax.swing.filechooser.FileNameExtensionFilter;public class RarAnnotate extends JFrame { /** * */ private static final long serialVersionUID = -7145152842194908145L; private JPanel contentPane; private JTextField rarFileField; private File rarFile; private JTextArea annotateArea; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { RarAnnotate frame = new RarAnnotate(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public RarAnnotate() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 5)); setContentPane(contentPane); JPanel panel = new JPanel(); contentPane.add(panel, BorderLayout.NORTH); panel.setLayout(new BorderLayout(0, 0)); JLabel lblrar = new JLabel("\u3000\u9009\u62E9RAR\u6587\u6863\uFF1A"); panel.add(lblrar, BorderLayout.WEST); JButton browseButton = new JButton("\u6D4F\u89C8"); browseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { do_browseButton_actionPerformed(e); } }); panel.add(browseButton, BorderLayout.EAST); rarFileField = new JTextField(); panel.add(rarFileField, BorderLayout.CENTER); rarFileField.setColumns(10); JPanel panel_1 = new JPanel(); FlowLayout flowLayout = (FlowLayout) panel_1.getLayout(); flowLayout.setHgap(25); contentPane.add(panel_1, BorderLayout.SOUTH); JButton annotateButton = new JButton("\u6DFB\u52A0/\u4FEE\u6539"); annotateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { do_annotateButton_actionPerformed(e); } }); panel_1.add(annotateButton); JButton closeButton = new JButton("\u5173\u95ED"); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { do_closeButton_actionPerformed(e); } }); panel_1.add(closeButton); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null), "\u6CE8\u91CA\u6587\u6863\uFF1A", TitledBorder.LEADING, TitledBorder.ABOVE_TOP, null, new Color(0, 0, 0))); contentPane.add(scrollPane, BorderLayout.CENTER); annotateArea = new JTextArea(); annotateArea.setLineWrap(true); scrollPane.setViewportView(annotateArea); } /** * 浏览按钮的事件处理方法 * * @param e */ protected void do_browseButton_actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser();// 创建文件选择器 chooser.setFileFilter(new FileNameExtensionFilter("RAR文档", "rar")); chooser.setAcceptAllFileFilterUsed(false); int option = chooser.showOpenDialog(this);// 显示文件打开对话框 if (option != JFileChooser.APPROVE_OPTION) return; rarFile = chooser.getSelectedFile();// 获取选择的rar文件 rarFileField.setText(rarFile.toString());// 显示rar文件到文本框 try { // 创建临时文件 File tempFile = File.createTempFile("rar", ".txt"); // 执行提取注释命令,把注释信息保存在临时文件中 Process process = getRuntime().exec("rar cw \"" rarFile "\" \"" tempFile "\" -y"); process.getOutputStream().close();// 关闭进程输出流 Scanner sc = new Scanner(process.getInputStream()); while (sc.hasNext()) { sc.nextLine();// 清空输入流 } process.getInputStream().close();// 关闭输入流 annotateArea.setText("");// 情况文本域内容 Scanner scan = new Scanner(tempFile);// 创建读取临时文件的扫描器 while (scan.hasNext()) { // 把注释信息显示到文本域控件中 annotateArea.append(scan.next() "\n"); } } catch (Exception e1) { e1.printStackTrace(); } } /** * 关闭按钮的事件监听器 * * @param e */ protected void do_closeButton_actionPerformed(ActionEvent e) { this.dispose(); } /** * 添加修改按钮的事件处理方法 * * @param e */ protected void do_annotateButton_actionPerformed(ActionEvent e) { String annotateStr = annotateArea.getText();// 获取注释文本 int length = annotateStr.getBytes().length;// 获取注释文本长度 if (length > 32767) {// 限制文本长度 JOptionPane.showMessageDialog(null, "注释长度不能大于32767"); return; } try { Process process = getRuntime().exec(// 执行添加注释命令 "rar c \"" rarFile "\""); // 把注释文本传递给注释命令 process.getOutputStream().write(annotateStr.getBytes()); process.getOutputStream().close();// 关闭输出流 process.getInputStream().close();// 关闭输入流 } catch (IOException e1) { e1.printStackTrace(); } }}
下载java为RAR压缩包添加注释用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论